﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace kb_24_the_game
{
    internal class ObstakelBal : ISprite
    {
        #region variabele declaratie

        public GraphicsDevice graphics { get; set; }

        public SpriteBatch spriteBatch { get; set; }

        public ContentManager content { get; set; }

        public Vector2 position { get; set; }

        private float moveSpeed = 5f;
        private Animation ballAnimation = new Animation();
        public Texture2D texture;
        public Vector2 ballPosition, tempCurrentFrame;
        public bool ballbounce = false;
        public string spelerDirectie;

        #endregion variabele declaratie

        public ObstakelBal(ContentManager content, Vector2 position)
        {
            this.content = content;
            ballAnimation.Initialize(position, new Vector2(8, 2));
            tempCurrentFrame = Vector2.Zero;
            Load();
        }

        public void Load()
        {
            texture = content.Load<Texture2D>("Level1Textures/BowlingBallAnimation");
            ballAnimation.AnimationImage = texture;
        }

        public void SetSpelerDirectie(string directie)
        {
            spelerDirectie = directie;
        }

        public void Update(GameTime gameTime)
        {
            ballAnimation.Active = true;
            ballPosition = ballAnimation.Position;
            if (ballbounce == true)
            {
                moveSpeed *= -1;
                ballbounce = false;
            }
            if (moveSpeed < 0)
            {
                tempCurrentFrame.Y = 1;
            }
            if (moveSpeed > 0)
            {
                tempCurrentFrame.Y = 0;
            }
            ballPosition = ballAnimation.Position;
            if (spelerDirectie == "links")
            {
                ballPosition.X -= moveSpeed - 3;
            }
            else if (spelerDirectie == "rechts")
            {
                ballPosition.X -= moveSpeed + 3;
            }
            else if (spelerDirectie == "stilstaan")
            {
                ballPosition.X -= moveSpeed;
            }
            tempCurrentFrame.X = ballAnimation.CurrentFrame.X;
            ballAnimation.Position = ballPosition;
            ballAnimation.CurrentFrame = tempCurrentFrame;
            ballAnimation.Update(gameTime);
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            ballAnimation.Draw(spriteBatch);
        }
    }
}
